home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / misc / emu / prlink_080b.lha / prlink-0.8.0b / src / prtrans8.c < prev    next >
C/C++ Source or Header  |  1995-04-06  |  4KB  |  189 lines

  1. #ifdef __linux__
  2. #include <unistd.h>
  3. #include <asm/io.h>
  4. #endif /* __linux__ */
  5. #include "prtrans.h"
  6.  
  7. unsigned baseaddr, stataddr, ctrladdr;
  8. unsigned ack;
  9.  
  10. int prinit (void) {
  11. #ifdef __linux__
  12.   if (ioperm (baseaddr, 3, 1))
  13.     return -1;
  14. #endif /* __linux__ */
  15.  
  16.   outb(8, baseaddr); /* set the -FLAG signal to high */
  17.   stataddr = baseaddr + 1;
  18.   ctrladdr = baseaddr + 2;
  19.   ack = 0x80 & inb(stataddr); /* get the current state of the BUSY line */
  20.  
  21.   return 0;
  22. }
  23.  
  24. void prclose (void) {
  25. }
  26.  
  27. void output (unsigned char byte) {
  28.   send (&byte, 1);
  29. }
  30.  
  31. unsigned input (void) {
  32.   unsigned char byte;
  33.  
  34.   receive (&byte, 1);
  35.   return byte;
  36. }
  37.  
  38. unsigned wait_input (void) {
  39.   register unsigned char data;
  40.  
  41.   outb(4, ctrladdr); /* set the bidirectional signals to input */
  42.   outb(0, baseaddr); /* drop -FLAG */
  43.  
  44.   while (ack == (0x80 & inb(stataddr))) /* wait for -BUSY to change */
  45.     usleep (SLEEP_TIME); /* wait before retrying */
  46.  
  47.   outb(8, baseaddr); /* raise -FLAG */
  48.  
  49.   data = inb(ctrladdr) & 0x0f; /* read the low nybble */
  50.  
  51.   outb(0, baseaddr); /* drop -FLAG */
  52.   while (ack != (0x80 & inb(stataddr))); /* wait for -BUSY to change */
  53.  
  54.   data |= inb(ctrladdr) << 4; /* read the high nybble */
  55.  
  56.   outb(8, baseaddr); /* raise -FLAG */
  57.  
  58.   return data ^ 0xbb;
  59. }
  60.  
  61. #if !defined(__i386__) && !defined(__GNU_C__)
  62. void send (unsigned char *buffer, unsigned length) {
  63.   register unsigned char byte;
  64.  
  65.   while (length--) {
  66.     byte = *buffer++ ^ 0x0b; /* invert bits 0, 1 and 3 */
  67.     outb(byte, ctrladdr);
  68.     outb(byte & ~8, baseaddr); /* drop the -FLAG to low */
  69.     while (ack == (0x80 & inb(stataddr))); /* wait for BUSY to change */
  70.     outb(8, baseaddr); /* raise -FLAG again */
  71.     ack ^= 0x80; /* store the new state of -BUSY */
  72.   }
  73. }
  74. #else /* __i386__ && __GNU_C__ */
  75. void send (unsigned char *buffer, unsigned length) {
  76.   asm ("push %%ebp
  77.     movw _baseaddr,%%dx
  78.     movl %1,%%ecx
  79.     movl %0,%%ebp
  80.  
  81. sloop:    movb (%%ebp),%%al
  82.     xorb $0xb,%%al
  83.     movb _ack,%%ah
  84.     addw $2,%%dx
  85.     outb %%al,%%dx
  86.     subw $2,%%dx
  87.     andb $0xf7,%%al
  88.     outb %%al,%%dx
  89.     incw %%dx
  90.  
  91. owait:    inb %%dx,%%al
  92.     andb $0x80,%%al
  93.     cmpb %%al,%%ah
  94.     je owait
  95.  
  96.     decw %%dx
  97.     xorb $0x80,%%ah
  98.     movb %%ah,_ack
  99.     movb $8,%%al
  100.     outb %%al,%%dx
  101.  
  102.     inc %%ebp
  103.     loop sloop
  104.     pop %%ebp"
  105.        : /* no outputs */
  106.        : "g" (buffer), "g" (length)
  107.        : "ax", "ecx", "dx");
  108. }
  109. #endif /* __i386__ && __GNU_C__ */
  110.  
  111. #if !defined(__i386__) && !defined(__GNU_C__)
  112. void receive (unsigned char *buffer, unsigned length) {
  113.   register unsigned char data;
  114.  
  115.   while (length--) {
  116.     outb(4, ctrladdr); /* set the bidirectional signals to input */
  117.     outb(0, baseaddr); /* drop -FLAG */
  118.     while (ack == (0x80 & inb(stataddr))); /* wait for -BUSY to change */
  119.     outb(8, baseaddr); /* raise -FLAG */
  120.  
  121.     data = inb(ctrladdr) & 0x0f; /* read the low nybble */
  122.  
  123.     outb(0, baseaddr); /* drop -FLAG */
  124.     while (ack != (0x80 & inb(stataddr))); /* wait for -BUSY to change */
  125.  
  126.     data |= inb(ctrladdr) << 4; /* read the high nybble */
  127.  
  128.     outb(8, baseaddr); /* raise -FLAG */
  129.  
  130.     *buffer++ = data ^ 0xbb;
  131.   }
  132. }
  133. #else /* __i386__ && __GNU_C__ */
  134. void receive (unsigned char *buffer, unsigned length) {
  135.   asm ("push %%ebp
  136.     movw _baseaddr,%%dx
  137.         movl %1,%%ecx
  138.         movl %0,%%ebp
  139.  
  140. rloop:    xorb %%al,%%al
  141.     outb %%al,%%dx
  142.     incw %%dx
  143.  
  144. iwait1:    inb %%dx,%%al
  145.     andb $0x80,%%al
  146.     cmpb _ack,%%al
  147.     je iwait1
  148.  
  149.     decw %%dx
  150.     movb $8,%%al
  151.     outb %%al,%%dx
  152.     addw $2,%%dx
  153.     movb $4,%%al
  154.     outb %%al,%%dx
  155.     inb %%dx,%%al
  156.     and $0xf,%%al
  157.     movb %%al,(%%ebp)
  158.  
  159.     subw $2,%%dx
  160.     xorb %%al,%%al
  161.     outb %%al,%%dx
  162.     incw %%dx
  163.  
  164. iwait2:    inb %%dx,%%al
  165.     andb $0x80,%%al
  166.     cmpb _ack,%%al
  167.     jne iwait2
  168.  
  169.     decw %%dx
  170.     movb $8,%%al
  171.     outb %%al,%%dx
  172.  
  173.     addw $2,%%dx
  174.     inb %%dx,%%al
  175.     subw $2,%%dx
  176.     salb $4,%%al
  177.     orb (%%ebp),%%al
  178.     xorb $0xbb,%%al
  179.     movb %%al,(%%ebp)
  180.  
  181.         inc %%ebp
  182.         loop rloop
  183.         pop %%ebp"
  184.        : /* no outputs */
  185.        : "g" (buffer), "g" (length)
  186.        : "ax", "ecx", "dx");
  187. }
  188. #endif /* __i386__ && __GNU_C__ */
  189.